function bindElements(){
    $("#Clear").bind('click', function(){
        $(":radio").attr('checked', '');
    });
    
    $(":radio").bind('dblclick', function(){
        $(this).attr("checked", '');
    });
    
	//bind submit button
    $("#Submit").bind('click', function(){
        $("div.entry").append('<div id="confirm_dialog" style="width: auto;"><p id="confirm_text"></p></div>');
        Terminate = $(':radio:checked.terminate');
        $.each(Terminate, function(i, terminate){
            var name = $("#" + $(terminate).parent().parent().parent().attr('id') + " td:eq(0)").text();
            $('#confirm_text').append(name + "<br />");
        });
        //creates jquery ui dialog box object
        var $confirm_dialog = $('#confirm_dialog').dialog({
            autoOpen: false,
            width: 'auto',
            modal: true,
            title: '<span class="ui-icon ui-icon-alert" style="float:left;"></span> Terminate all accounts?',
            resizable: false,
            open: function(event, ui){
                $("div.ui-dialog-titlebar").width($(".ui-dialog").width());
            },
            close: function(event, ui){
                $(this).dialog("destroy")
            },
            buttons: {
                "Terminate All": function(){
                    $(this).dialog("close");
                    submitProcessor();
                },
                Cancel: function(){
                    $(this).dialog("close");
                    return false;
                }
            }
        });
        if( Terminate.length > 0 ){
            $confirm_dialog.dialog('open');
        }else{
            submitProcessor();
        }

    });
}



function submitProcessor(){    
    ExtendTerminate = $(':radio:checked');            
    $.each(ExtendTerminate,function(i, extend_terminate){
        var nonscfmasterid = $(extend_terminate).parent().parent().parent().attr('id');
        var expirationdate = $("#" + nonscfmasterid + " input[id='ExpirationDate']").val();
        var employeeuseraccount = $("#" + nonscfmasterid + " input[id='EmployeeUserAccount']").val();
        var employeedn = $("#" + nonscfmasterid + " input[id='EmployeeDN']").val();
        var EmployeeObj = {NonSCFMasterID: nonscfmasterid, 
            ExtendTerminate: $(extend_terminate).val(), 
            EmployeeUserAccount: employeeuseraccount, 
            EmployeeDN: employeedn, 
            ExpirationDate: expirationdate};
        var FormAction = ( $(extend_terminate).val() == 2 ? $("#FormActionTerminate").val() : $("#FormActionExtend").val() );            
        $.ajax({
            type:'POST', url: FormAction, dataType: 'json', async: false, data: EmployeeObj,
            success: function(json) { jsonData = json; },
            complete: function(){ return false; },
            error: function(){ return false; }
        });
    });
    location.href = 'Review.cfm'     
};


function confirmTermination(){    
    $( "#confirm_dialog" ).dialog({
        resizable: false,
        modal: true,
        buttons: {
            "Terminate All": function() {$( this ).dialog( "close" ); return {Confirm: 1 }; },
            Cancel: function() { $( this ).dialog( "close" ); return  {Confirm: 0}; }
        }
    });
     
};


$(function(){
	bindElements();
});